package com.gjy.spring.s8;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-12-20 10:52:20
 */
@RestController
@RequestMapping("/s8")
public class MyController {

    @Autowired
    @Lazy
    private BeanForRequest beanForRequest;
    // server.servlet.session.timeout=5s 设置session超时时间
    @Autowired
    @Lazy
    private BeanForSession beanForSession;
    @Autowired
    @Lazy
    private BeanForApplication beanForApplication;
    @Autowired
    @Lazy
    private BeanForNull beanForNull;

    @GetMapping(value = "/test", produces = MediaType.TEXT_HTML_VALUE)
    public String test(HttpServletRequest request,
                       HttpSession session) {
        ServletContext context = request.getServletContext();

        return "<ul>" +
                "<li> request scope: " + beanForRequest + "</li>" +
                "<li> session scope: " + beanForSession + "</li>" +
                "<li> application scope: " + beanForApplication + "</li>" +
                "<li> null scope: " + beanForNull + "</li>" +
                "</ul>";
    }
}
